<template>
  <div class="user-info">
    <!-- 个人信息 -->
    <el-form label-width="220px">
      <!--手机 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="手机">
            <el-input v-model="userInfo.mobile" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 工号 入职时间 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="入职时间">
            <el-date-picker
              v-model="userInfo.timeOfEntry"
              type="date"
              class="inputW"
              value-format="yyyy-MM-dd"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 员工照片 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="员工头像">
            <!-- 放置上传图片 -->
            <!-- <el-image :src="userInfo.staffPhoto || src">
              <div slot="placeholder" class="image-slot">
                加载中<span class="dot">...</span>
              </div>
            </el-image> -->
            <uplodeImage ref="staffPhoto" @upPhoto="getUrl" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 保存个人信息 -->
      <el-row class="inline-info" type="flex" justify="center">
        <el-col :span="12">
          <el-button type="primary" @click="onSubmit">保存更新</el-button>
          <el-button @click="$router.back()">返回</el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { getUserDetailById, setUserDetailById } from '@/api/employees'
export default {
  data() {
    return {
      userId: this.$route.query.id,
      src: 'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg',
      userInfo: {
        username: '',
        password: ''
      },
      staffPhoto: ''
    }
  },
  created() {

  },
  mounted() {
    this.getUserDetail()
  },
  methods: {
    //   图片上传组件返回的url
    getUrl(url) {
      this.userInfo.staffPhoto = url
    },
    async getUserDetail() {
      const res = await getUserDetailById(this.userId)
      console.log(res)
      this.userInfo = res.data.data
      this.$refs.staffPhoto.imageUrl = this.userInfo.staffPhoto
    },
    async onSubmit() {
      try {
        const res = await setUserDetailById(this.userId, this.userInfo)
        console.log(res)
        if (res.data.success === true) {
          this.$message.success(res.data.message)
          this.userInfo = res.data.data
          this.$router.back()
        } else {
          this.$message.error(res.data.message)
        }
      } catch (error) {
        this.$message.error(error.message)
      }
    }
    // upload(params) {
    //   console.log('上传', params)
    // },

  }
}
</script>

<style scoped>
  .user-info{
    padding-top:20px;
  }
  .progress {
  position: absolute;
  display: flex;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  background: #fff;
}
    .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
